import React from 'react'
import {
  Form,
  Input,
  Button, 
} from 'antd-mobile'
import { getLoginApi } from '../../api/request' 
import { useNavigate } from 'react-router-dom'
function index() { 
  const nav=useNavigate()
  const onFinish=async(val)=>{ 
      console.log(val)
      const resp= await getLoginApi(val)
      console.log(resp);
      localStorage.setItem('token',resp.data.data.token)
      alert('登陆成功')
      nav('/')
  } 
  return (
    <div> 
        <Form
        onFinish={onFinish}
        layout='horizontal'
        footer={
          <Button block type='submit' color='primary' size='large' >
            登录
          </Button>
        }
      > 
        <Form.Item
          name='username'
          label='用户名'
          rules={[{ required: true, message: '用户名不能为空' }
          ]}
        >
          <Input  placeholder='请输入用户名' />
        </Form.Item>
        <Form.Item
          name='password'
          label='密码'
          rules={[{ required: true, message: '密码不能为空' }]}
        >
          <Input  placeholder='请输入密码' />
        </Form.Item>
        </Form>
    </div>
  )
}

export default index